package _09_优先级队列;

import _01_第一季._00_公共接口.Queue;
import _08_堆.BinaryHeap;

import java.util.Comparator;

/*
    优先级队列，可以使用堆实现
    JDK中的优先级队列是由一个最小堆实现
 */
public class PriorityQueue<E> implements Queue<E> {
    private BinaryHeap<E> heap;

    private PriorityQueue(Comparator<E> comparator){
        heap = new BinaryHeap<>(comparator);
    }

    private PriorityQueue(){
        this(null);
    }

    @Override
    public int size() {
        return heap.size();
    }

    @Override
    public boolean isEmpty() {
        return heap.isEmpty();
    }

    @Override
    public void enQueue(E element) {
        heap.add(element);
    }

    @Override
    public E deQueue() {
        return heap.remove();
    }

    @Override
    public E front() {
        return heap.get();
    }

    @Override
    public void clear() {
        heap.clear();
    }
}
